package com.zrar.ak.gkpt.controller.record;


import com.zrar.ak.gkpt.model.vo.UserVO;
import com.zrar.ak.gkpt.service.record.IBusinessFundManageService;
import com.zrar.ak.gkpt.service.user.IUserService;
import com.zrar.ak.gkpt.util.FormDataParameter;
import com.zrar.ak.gkpt.util.JsonPageResult;
import com.zrar.ak.gkpt.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: BusinessFundManageController
 * @Description 资金管理Controller层
 * @Author HuangKeXin
 * @Time 2020/04/4
 */
@RestController
@RequestMapping("/foundmanage")
@Api(tags = "资金管理相关接口")
public class BusinessFundManageController {
    @Autowired
    private IBusinessFundManageService businessFundManageService;
    @Autowired
    private IUserService userService;
    @RequestMapping(value = "foundManageSave", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "资金管理明细信息保存", httpMethod = "POST", notes = "资金管理明细信息保存")
    public JsonResult foundManageDetailsSave(HttpServletRequest request,
                                           @ApiParam(name = "formDataParameter", value = "资金管理明细信息保存数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult =businessFundManageService.foundManageDetailsSave(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "foundManageUpdate", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "资金管理明细信息修改", httpMethod = "POST", notes = "资金管理明细信息修改")
    public JsonResult foundManageDetailsUpdate(HttpServletRequest request,
                                             @ApiParam(name = "formDataParameter", value = "资金管理明细信息修改数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessFundManageService.foundManageDetailsUpdate(jsonResult, formDataJson, userVO);
        return jsonResult;
    }


    @RequestMapping(value = "foundManageAdjustSave", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "资金调整信息保存", httpMethod = "POST", notes = "资金调整信息保存")
    public JsonResult foundManageAdjustSave(HttpServletRequest request,
                                            @ApiParam(name = "formDataParameter", value = "资金调整信息保存数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult =businessFundManageService.foundManageAdjustSave(jsonResult, formDataJson, userVO);
        return jsonResult;
    }

    @RequestMapping(value = "foundManageAdjustUpdate", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "资金调整信息修改", httpMethod = "POST", notes = "资金调整信息修改")
    public JsonResult foundManageAdjustUpdate(HttpServletRequest request,
                                              @ApiParam(name = "formDataParameter", value = "资金调整信息修改数据参数") @RequestBody FormDataParameter formDataParameter){
        JsonResult jsonResult = new JsonResult();
        String formDataJson = formDataParameter.getFormDataJson();
        UserVO userVO = userService.getUserInformation(request);
        jsonResult = businessFundManageService.foundManageAdjustUpdate(jsonResult, formDataJson, userVO);
        return jsonResult;
    }


    @RequestMapping(value = "foundManageAdjustGet", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据建设单位编码获取资金管理明细", httpMethod = "GET", notes = "根据建设单位编码获取资金管理明细")
    public JsonResult foundManageDetailsGetByUnitId(HttpServletRequest request,
                                                    @ApiParam(name = "unitId", value = "建设单位编码") @RequestParam String unitId){
        JsonResult jsonResult = new JsonResult();
        jsonResult = businessFundManageService.foundManageDetailsGetByUnitId(jsonResult, unitId);
        return jsonResult;
    }
   /* @RequestMapping(value = "accountInfoGet", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据单位ID获取台账信息", httpMethod = "GET", notes = "根据单位ID获取台账信息")
    public JsonResult accountInfoGetByUnitId(HttpServletRequest request,
                                             @ApiParam(name = "unitId", value = "单位ID") @RequestParam String unitId){
        JsonResult jsonResult = new JsonResult();
        jsonResult = businessAccountInfoService.accountInfoGetByUnitId(jsonResult, unitId);
        return jsonResult;
    }
*/
    @RequestMapping(value = "delete", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "根据建设单位编码将对应的资金明细信息置为无效", httpMethod = "GET", notes = "根据建设单位编码将对应的资金明细信息置为无效")
    public JsonResult deleteFoundManageDetailsByUnitId(HttpServletRequest request,
                                                       @ApiParam(name = "unitId", value = "建设单位编码") @RequestParam String unitId,
                                                       @ApiParam(name = "foundType", value = "资金类型(1:资金明细信息和资金调整明细信息执行删除操作 2:资金调整明细信息执行删除操作))") @RequestParam(value = "foundType", required = false, defaultValue = "1") String foundType){
        JsonResult jsonResult = new JsonResult();
        jsonResult =businessFundManageService.deleteFoundManageDetailsByUnitId(jsonResult, unitId, foundType);
        return jsonResult;
    }

    @RequestMapping(value = "foundManageAdjustList", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "获取资金明细信息列表-分页查询和条件查询", httpMethod = "GET", notes = "获取资金明细信息列表-分页查询和条件查询")
    public JsonPageResult getFoundManageDetailsList(HttpServletRequest request,
                                             @ApiParam(name = "currentPage", value = "当前页") @RequestParam int currentPage,
                                             @ApiParam(name = "pageSize", value = "每页条数限制") @RequestParam int pageSize,
                                             @ApiParam(name = "unitName", value = "建设单位名称(模糊查询)") @RequestParam(value = "unitName",required=false) String unitName){
        JsonPageResult jsonResult = new JsonPageResult();
        jsonResult = businessFundManageService.getFoundManageDetailsList(jsonResult, currentPage,pageSize,unitName);
        return jsonResult;
    }

}
